package javolution.xml.stream;

import javax.realtime.MemoryArea;
import javolution.lang.Reusable;
import javolution.text.CharArray;
import javolution.text.Text;
import javolution.xml.sax.Attributes;

/* loaded from: classes2.dex */
final class AttributesImpl implements Attributes, Reusable {
    private static final CharArray CDATA = new CharArray("CDATA");
    private int _length;
    private final NamespacesImpl _namespaces;
    private CharArray[] _localNames = new CharArray[16];
    private CharArray[] _prefixes = new CharArray[16];
    private CharArray[] _qNames = new CharArray[16];
    private CharArray[] _values = new CharArray[16];

    public AttributesImpl(NamespacesImpl namespacesImpl) {
        this._namespaces = namespacesImpl;
    }

    private void increaseCapacity() {
        MemoryArea.getMemoryArea(this).executeInArea(new Runnable() { // from class: javolution.xml.stream.AttributesImpl.1
            @Override // java.lang.Runnable
            public void run() {
                int i = AttributesImpl.this._length * 2;
                CharArray[] charArrayArr = new CharArray[i];
                System.arraycopy(AttributesImpl.this._localNames, 0, charArrayArr, 0, AttributesImpl.this._length);
                AttributesImpl.this._localNames = charArrayArr;
                CharArray[] charArrayArr2 = new CharArray[i];
                System.arraycopy(AttributesImpl.this._prefixes, 0, charArrayArr2, 0, AttributesImpl.this._length);
                AttributesImpl.this._prefixes = charArrayArr2;
                CharArray[] charArrayArr3 = new CharArray[i];
                System.arraycopy(AttributesImpl.this._qNames, 0, charArrayArr3, 0, AttributesImpl.this._length);
                AttributesImpl.this._qNames = charArrayArr3;
                CharArray[] charArrayArr4 = new CharArray[i];
                System.arraycopy(AttributesImpl.this._values, 0, charArrayArr4, 0, AttributesImpl.this._length);
                AttributesImpl.this._values = charArrayArr4;
            }
        });
    }

    public void addAttribute(CharArray charArray, CharArray charArray2, CharArray charArray3, CharArray charArray4) {
        if (this._length >= this._localNames.length) {
            increaseCapacity();
        }
        CharArray[] charArrayArr = this._localNames;
        int i = this._length;
        charArrayArr[i] = charArray;
        this._prefixes[i] = charArray2;
        this._qNames[i] = charArray3;
        CharArray[] charArrayArr2 = this._values;
        this._length = i + 1;
        charArrayArr2[i] = charArray4;
    }

    @Override // javolution.xml.sax.Attributes
    public int getIndex(CharSequence charSequence) {
        for (int i = 0; i < this._length; i++) {
            if (this._qNames[i].equals((Object) charSequence)) {
                return i;
            }
        }
        return -1;
    }

    @Override // javolution.xml.sax.Attributes
    public int getIndex(CharSequence charSequence, CharSequence charSequence2) {
        CharArray namespaceURINullAllowed;
        if (charSequence != null) {
            for (int i = 0; i < this._length; i++) {
                if (this._localNames[i].equals((Object) charSequence2) && (namespaceURINullAllowed = this._namespaces.getNamespaceURINullAllowed(this._prefixes[i])) != null && namespaceURINullAllowed.equals((Object) charSequence)) {
                    return i;
                }
            }
            return -1;
        }
        throw new IllegalArgumentException("null namespace URI is not allowed");
    }

    @Override // javolution.xml.sax.Attributes
    public int getLength() {
        return this._length;
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getLocalName(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return this._localNames[i];
    }

    public CharArray getPrefix(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return this._prefixes[i];
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getQName(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return this._qNames[i];
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getType(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return CDATA;
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getType(CharSequence charSequence) {
        if (getIndex(charSequence) >= 0) {
            return CDATA;
        }
        return null;
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getType(CharSequence charSequence, CharSequence charSequence2) {
        if (getIndex(charSequence, charSequence2) >= 0) {
            return CDATA;
        }
        return null;
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getURI(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return this._namespaces.getNamespaceURINullAllowed(this._prefixes[i]);
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getValue(int i) {
        if (i < 0 || i >= this._length) {
            return null;
        }
        return this._values[i];
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getValue(CharSequence charSequence) {
        int index = getIndex(charSequence);
        if (index >= 0) {
            return this._values[index];
        }
        return null;
    }

    @Override // javolution.xml.sax.Attributes
    public CharArray getValue(CharSequence charSequence, CharSequence charSequence2) {
        int index = getIndex(charSequence, charSequence2);
        if (index >= 0) {
            return this._values[index];
        }
        return null;
    }

    @Override // javolution.lang.Reusable
    public void reset() {
        this._length = 0;
    }

    public String toString() {
        Text valueOf = Text.valueOf('[');
        Text valueOf2 = Text.valueOf('=');
        Text valueOf3 = Text.valueOf((Object) ", ");
        int i = 0;
        while (i < this._length) {
            valueOf = valueOf.concat(Text.valueOf(this._qNames[i]).concat(valueOf2).concat(Text.valueOf(this._values[i])));
            i++;
            if (i != this._length) {
                valueOf = valueOf.concat(valueOf3);
            }
        }
        return valueOf.concat(Text.valueOf(']')).toString();
    }
}
